using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Meat.Resources;
using Microsoft.Xna.Framework.Content;

namespace Meat.Rendering
{
    public class UserVertexResource<T> : ICustomResourceType, IVertexResource where T : struct, IVertexType
    {
        T[] m_Vertices;

        int m_Count;
        PrimitiveType m_Type;

        public int StartIndex
        { get; set; }

        public int PrimitiveCount
        { get { return m_Count; } }

        public PrimitiveType PrimitiveType
        { get { return m_Type; } }

        public T[] Buffer
        { get { return m_Vertices; } }

        public UserVertexResource(List<T> vertices, int primitiveCount, PrimitiveType primitiveType)
        {
            m_Vertices = vertices.ToArray();
            m_Count = primitiveCount;
            m_Type = primitiveType;
        }

        public void Load(ContentManager content, GraphicsDevice device)
        {}

        public void Unload()
        {}

        public void PreDraw(GraphicsDevice device)
        {}

        public void Draw(GraphicsDevice device)
        {
            device.DrawUserPrimitives<T>(PrimitiveType, Buffer, StartIndex, PrimitiveCount);
        }
    }
}
